package com.itheima.api_demo.object_demo;

//public class Student {
public class Student extends Object {
    private String name;
    private int age;


    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {// Object o = new Student("李沁" , 19);
        /*
            this = s1
            o    = s2
         */
        // 比较的是地址是否相等!
        // 提高代码的执行效率
        if (this == o){
            return true;
        }
        /*
            || : 具备短路作用 , 左边为true右边不执行
            getClass() : 获取一个类的字节码对象 , 同一个类的字节码对象一定相等!
            this.getClass() != o.getClass() : 规范比较的两个对象的类型必须一致!
            提高代码的健壮性
         */
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        // 向下转型
        // student = s2
        Student student = (Student) o;

        if (this.age != student.age) {
            return false;
        }
        /*
            name != null : 提高代码的健壮性
         */
        return this.name != null ? this.name.equals(student.name) : student.name == null;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
